package com.deer.wms.system.manage.web;

import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.deer.wms.project.root.util.RedisUtil;
import com.deer.wms.system.manage.service.CellLedService;
import com.deer.wms.system.manage.test.*;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.*;

@Api(description = "亮灯系统api")
@RestController
@RequestMapping("/led")
public class LedController {

    @Autowired
    private CellLedService cellLedService;
    @Autowired
    private RedisUtil redisUtil;


    /**
     * 通过仓库编码集合批量控制灯光
     * @param cellCodes 仓库编码
     * @param color 颜色
     * @param time  时长(s)
     * @param lighttype 亮----1  灭----0
     * @return
     */
    @PostMapping("/ledControl")
    public Result ledControl(@RequestBody List<String> cellCodes, String color, Long time, Integer lighttype) {
        Result result = cellLedService.ledControl(cellCodes, color, time, lighttype);
        return result;
    }

    /**
     * 接收设备心跳接口
     * @return
     */
    @PostMapping("/heartbeat")
    public Result heartbeat (HttpServletRequest request,@RequestBody HeartbeatDto heartbeatDto){
        cellLedService.heartbeat(request,heartbeatDto);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 给设备设置心跳接口地址
     * @param ip 设备的ip地址
     * @return
     */
    @GetMapping("/setServerIp")
    public Result setServerIp (String ip){
        Result result = cellLedService.setServerIp(ip);
        return result;
    }

    /**
     * 七彩循环全亮(检查)
     * @param ip 设备的ip地址
     * @return
     */
    @GetMapping("/ledcheck")
    public Result ledcheck (String ip){
        Result result = cellLedService.ledcheck(ip);
        return result;
    }

    /**
     * 设置料架左右分隔数
     * @param ip 设备的ip地址
     * @num 分隔数
     * @return
     */
    @GetMapping("/setmidnum")
    public Result setmidnum (String ip,Integer num){
        Result result = cellLedService.setmidnum(ip, num);
        return result;
    }

    /**
     * 设置料架库位总数
     * @param ip 设备的ip地址
     * @return
     */
    @GetMapping("/settotalnum")
    public Result settotalnum (String ip,Integer num){
        Result result = cellLedService.settotalnum(ip, num);
        return result;
    }

    /**
     * 全亮/灭
     * @param ip 设备的ip地址
     * @return
     */
    @PostMapping("/allledcontrol")
    public Result allledcontrol (@RequestBody AllLedControlDto allLedControlDto,String ip){
        cellLedService.allledcontrol(allLedControlDto,ip);
        return ResultGenerator.genSuccessResult();
    }

}
